#include "Math.hpp"
#include "Camera.hpp"

namespace fge
{

Camera::Camera(int width, int height)
{
	SetPosition(fge::Vector2(0, 0));
	SetRotation(0);
	SetZoom(1);
	SetDimensions(fge::Vector2(static_cast<float>(width), static_cast<float>(height)));
}

void Camera::SetDimensions(const fge::Vector2 &dimensions)
{
	this->dimensions = dimensions;
}

void Camera::SetPosition(const fge::Vector2 &position)
{
	this->position = position;
}

void Camera::SetRotation(const float &angle)
{
	this->angle = angle;
}

void Camera::SetZoom(const float &zoom)
{
	this->zoom = zoom;
}

fge::Matrix3 Camera::GetTransform() const
{
	return fge::CreateTranslationMatrix(dimensions.X() / 2, dimensions.Y() / 2) *
		fge::CreateRotationMatrix(angle) *
		fge::CreateScaleMatrix(zoom, zoom) *
		fge::CreateTranslationMatrix(-position.X(), -position.Y());
}

fge::Vector2 Camera::GetTopLeft() const
{
	return fge::Vector2(position.X() - dimensions.X() / 2 / zoom, position.Y() - dimensions.Y() / 2 / zoom);
}

fge::Vector2 Camera::GetBottomRight() const
{
	return fge::Vector2(position.X() + dimensions.X() / 2 / zoom, position.Y() + dimensions.Y() / 2 / zoom);
}

}
